package com.rui1024.dao.impl;


import com.rui1024.dao.SpecialtyDao;
import com.rui1024.pojo.Specialty;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


public class SpecialtyDaoImpl implements SpecialtyDao {

    //查询所有菜单数据
    public Specialty find(String name,Connection con) throws SQLException {
        String sql = "select * from cjq where name = ? ";
//        String sql = "select * from cjq where name LIKE '%'?'%'";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setString(1, name);
        ResultSet rs = pstmt.executeQuery();
        // 处理结果集
        while (rs.next()) {
            Specialty specialty = new Specialty();
            specialty.setName(rs.getString("name"));
            specialty.setSrc(rs.getString("src"));
            specialty.setIntroduce(rs.getString("introduce"));
            return specialty;
        }
        return null;
    }


    public List< Specialty > findAll(Connection con) throws SQLException {
        String sql="select * from cjq";
        PreparedStatement pstmt = con.prepareStatement(sql);
        ResultSet rs = pstmt.executeQuery();
        List < Specialty > list = new ArrayList < Specialty > ();
        while (rs.next()) {
            Specialty specialty = new Specialty();
            specialty.setName(rs.getString("name"));
            specialty.setSrc(rs.getString("src"));
            specialty.setIntroduce(rs.getString("introduce"));
            list.add(specialty);
        }
        return list;

    }

}
